//
//  HMNewClassListVC.m
//  优学荟管理系统
//
//  Created by 陈辉明 on 2017/12/25.
//  Copyright © 2017年 星道三好. All rights reserved.
//
#import "ProgramStudyViewController.h"
#import "HMNewClassListVC.h"
#import "HMNewClassListCell.h"
#import "HNCourseListVC.h"
#import "ZYThreeGoodYoungPeopleController.h"
    #import "PackageListVC.h"
#import "HMDownClassVC.h"
#import "ZYNewListCommonCourseController.h"
#import "ZYNewEditionOfIntensiveCourseController.h"
#import "ZYAlreadyDownsController.h"

@interface HMNewClassListVC () <UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property(nonatomic,strong) NSArray *dataSouce;



@end

@implementation HMNewClassListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpTableView];
    self.title = @"课程列表";
    [self setNavigationItems];
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(255,255,255)}]; //设置标题颜色
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(47, 204, 138)] forBarMetrics:(UIBarMetricsDefault)];//设置导航栏颜色

    [SVProgressHUD dismiss];
}


- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
         
}

//自定义导航栏左边和右边按钮
- (void)setNavigationItems {
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTargat:self action:@selector(leftBarButtonItemAction) image:@"icon_back_student_sign" highImage:@"icon_back_student_sign"];
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(0, 0, 50, 30);
    [button setTitle:@"已下架" forState:(UIControlStateNormal)];
    [button setTitleColor:RGBColor(102, 102, 102) forState:(UIControlStateNormal)];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightItem;
}



#pragma mark - UITableViewDataSource


- (void)setUpTableView {
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"HMNewClassListCell" bundle:nil] forCellReuseIdentifier:@"HMNewClassListCellId"];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 60;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSouce.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HMNewClassListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HMNewClassListCellId" forIndexPath:indexPath];
    cell.namePic.image = [UIImage imageNamed:self.dataSouce[indexPath.row][@"pic"]];
    cell.nameLabel.text = self.dataSouce[indexPath.row][@"name"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - 点击事件

- (void)buttonAction {
//    HMDownClassVC *vc = [HMDownClassVC new];
    ZYAlreadyDownsController *vc =[ZYAlreadyDownsController new];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)leftBarButtonItemAction{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.row) {//金牌课程
//        HNCourseListVC *VC = [[HNCourseListVC alloc] init];
        ZYNewListCommonCourseController *vc = [ZYNewListCommonCourseController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (1 == indexPath.row) {//三好小当家
        ZYThreeGoodYoungPeopleController *VC = [[ZYThreeGoodYoungPeopleController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
    if (2 == indexPath.row) {//加强课
//        HNStrengtheningClassApplicationVC *VC = [[HNStrengtheningClassApplicationVC alloc] init];
        ZYNewEditionOfIntensiveCourseController *vc = [ZYNewEditionOfIntensiveCourseController new];//新版加强课
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (3 == indexPath.row) {//套餐课
        PackageListVC *VC = [[PackageListVC alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
    if (4 == indexPath.row) {//少年编程
        ZYNewListCommonCourseController *vc = [ZYNewListCommonCourseController new];
        vc.IsProgramStudy = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - 数据源
-(NSArray *)dataSouce {
    if (!_dataSouce) {
        _dataSouce = @[@{@"pic":@"icon_class_default",@"name":@"金牌课程"},
                       @{@"pic":@"icon_xiaodangjia_default",@"name":@"三好小当家"},
                       @{@"pic":@"icon_jiaqiangke_default",@"name":@"金牌加强课"},
                       @{@"pic":@"icon_taocan_default",@"name":@"套餐课"},@{@"pic":@"mine_icon_reobot_default-1",@"name":@"少年编程"}];
    }
    return _dataSouce;
}


@end
